local liaoyuan = fk.CreateSkill {
  name = "xx__liaoyuan",
}

Fk:loadTranslationTable{
  ["xx__liaoyuan"] = "燎原",
  [":xx__liaoyuan"] = "出牌阶段限两次，你可以将一张牌当火【杀】或【火攻】使用。若未造成伤害，你可以用此牌拼点，赢的角色视为对没赢角色使用另一牌名且伤害+1。",
  ["#liaoyuan"] = "将一张牌当火【杀】或【火攻】使用",
  ["#ask"] = "与选择的角色拼点",
  ["@@xx__liaoyuan"] = "燎原"
}

liaoyuan:addEffect("viewas", {
  anim_type = "offensive",
  prompt = "#liaoyuan",
  interaction = UI.CardNameBox {choices = {"fire__slash", "fire_attack"}},
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and table.contains(player:getHandlyIds(), to_select)
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = liaoyuan.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_play = function(self, player)
    return player:usedEffectTimes(self.name, Player.HistoryPhase) < 2
  end,
})

liaoyuan:addEffect(fk.CardUseFinished, {
  can_refresh = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, liaoyuan.name) and
      not data.damageDealt and not data.extraUse and data.card.name == "fire__slash" and data.card
      and #Card:getIdList(data.card) ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p)
      return p:getHandcardNum()>0 and player ~= p
    end)
        local pl = room:askToChoosePlayers(player, {
        prompt = "#ask",
        targets = targets,
        min_num = 1,
        max_num = 1,
        skill_name = liaoyuan.name,
        cancelable = true
        })
        local pindian = player:pindian({pl[1]}, liaoyuan.name ,data.card)
        local from, to
        if pindian.results[pl[1]].winner == player then
        from, to = player, pl[1]
        elseif pindian.results[pl[1]].winner == pl[1] then
        from, to = pl[1], player
        end
    if from ~= to and not from.dead and not to.dead then
        room:addPlayerMark(to, "@@xx__liaoyuan",1)
       room:useVirtualCard("fire_attack", nil, from, to, liaoyuan.name)
       room:addPlayerMark(from, MarkEnum.SlashResidue, 1)
       player.room:setPlayerMark(to, "@@xx__liaoyuan", 0)
    end
  end,
})

liaoyuan:addEffect(fk.CardUseFinished, {
  can_refresh = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, liaoyuan.name) and
      not data.damageDealt and not data.extraUse and data.card.trueName == "fire_attack" and data.card
      and #Card:getIdList(data.card) ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p)
      return p:getHandcardNum()>0
    end)
        local pl = room:askToChoosePlayers(player, {
        prompt = "#ask",
        targets = targets,
        min_num = 1,
        max_num = 1,
        skill_name = liaoyuan.name,
        cancelable = true
        })
        local pindian = player:pindian({pl[1]}, liaoyuan.name ,data.card)
        local from, to
        if pindian.results[pl[1]].winner == player then
        from, to = player, pl[1]
        elseif pindian.results[pl[1]].winner == pl[1] then
        from, to = pl[1], player
        end
    if from ~= to and not from.dead and not to.dead then
       room:addPlayerMark(to, "@@xx__liaoyuan",1)
       room:useVirtualCard("fire__slash", nil, from, to, liaoyuan.name)
       room:addPlayerMark(from, MarkEnum.SlashResidue, 1)
       player.room:setPlayerMark(to, "@@xx__liaoyuan", 0)
    end
  end,
})

liaoyuan:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return  data.to:getMark("@@xx__liaoyuan") > 0 and
      data.card and (data.card.name == "fire__slash" or data.card.name == "fire_attack") and table.contains(data.card.skillNames, "xx__liaoyuan")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data:changeDamage(1)
    player.room:setPlayerMark(data.to, "@@xx__liaoyuan", 0)
  end,
})

return liaoyuan
